package com.lzh.chatnote.common.mqConsumer;


import com.lzh.chatnote.chat.domain.dto.message.PushMsgDTO;
import com.lzh.chatnote.chat.domain.enums.PushTypeEnum;
import com.lzh.chatnote.common.constant.MQConstant;
import com.lzh.chatnote.webSocket.service.WebSocketService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@RocketMQMessageListener(consumerGroup = MQConstant.PUSH_GROUP, topic = MQConstant.PUSH_TOPIC, messageModel = MessageModel.BROADCASTING)
public class PushMsgOnlineUserConsumer implements RocketMQListener<PushMsgDTO> {


    @Resource
    private WebSocketService webSocketService;


    @Override
    public void onMessage(PushMsgDTO pushMsgDTO) {
        PushTypeEnum pushTypeEnum = PushTypeEnum.of(pushMsgDTO.getPushType());
        switch (pushTypeEnum) {
            case GROUP:
                //群推送
                webSocketService.pushListUser(pushMsgDTO);
                break;
            case ALL:
                //全员推送
                webSocketService.pushOnlineAllUser(pushMsgDTO);
                break;
        }
    }
}
